package quests.Q358_IllegitimateChildOfAGoddess;

import net.sf.l2j.gameserver.model.actor.L2Npc;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.model.quest.Quest;
import net.sf.l2j.gameserver.model.quest.QuestState;
import net.sf.l2j.gameserver.model.quest.State;

public class Q358_IllegitimateChildOfAGoddess extends Quest
{
	private final static String qn = "Q358_IllegitimateChildOfAGoddess";
	
	//rewards
	private static int[] Rewards = new int[] { 6329, 6330, 6331, 6332, 6333, 6334, 6335, 6336, 6337, 6338, 6338, 6339, 6340, 5364, 5365, 5366, 5367 };
	//Npcs
	private static final int Oltlin = 30862;
	//Q-items
	private static final int Scale = 5868;
	
	public Q358_IllegitimateChildOfAGoddess(int questId, String name, String descr)
	{
		super(questId,name,descr);
		
		questItemIds = new int[] { Scale };
		
		addStartNpc(Oltlin);
		addTalkId(Oltlin);
		addKillId(20672, 20673);
	}
	
	@Override
	public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
	{
		String htmltext = event;
		QuestState st = player.getQuestState(qn);
		if (st == null)
			return htmltext;
		
		if (event.equalsIgnoreCase("30826-5.htm"))
		{
			st.setState(State.STARTED);
			st.set("cond", "1");
			st.playSound("ItemSound.quest_accept");
		}	
		return htmltext;
	}
	
	
	@Override
	public String onTalk(L2Npc npc, L2PcInstance player)
	{
		String htmltext = Quest.getNoQuestMsg(player);
		QuestState st = player.getQuestState(qn);
		if (st == null)
			return htmltext;
		
		int cond = st.getInt("cond");
		
		switch(st.getState())
		{
			case State.CREATED:
				if (player.getLevel() < 63)
				{
					htmltext = "30862-1.htm";
					st.exitQuest(true);
				}
				else
					htmltext = "30862-2.htm";
				break;
			case State.STARTED:
				int count = st.getQuestItemsCount(Scale);
				
				if (cond == 2)
				{
					if (count < 108)
						htmltext = "30862-6.htm";
					else
					{
						st.takeItems(Scale, -1);
						for (int i = 0; i < Rewards.length; i++)
						{
							st.giveItems(st.getRandom(i), 1);
						}
						st.playSound("ItemSound.quest_finish");
						htmltext = "30862-7.htm";
						st.exitQuest(true);
					}
				}
				break;			
		}
		
		return htmltext;
	}
	
	public String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
	{
		QuestState st = player.getQuestState(qn);
		if (st == null)
			return null;
		int cond = st.getInt("cond");
		if (cond == 1)
		{
			int Drop = 0;
			int count = st.getQuestItemsCount(Scale);
			Drop = st.getRandom(3);
					
			if (count + Drop > 108)
				Drop = 108 - count;
			else if (count + Drop == 108)
			{
				st.playSound("ItemSound.quest_middle");
				st.set("cond", "2");
			}
			else
				st.playSound("ItemSound.quest_itemget");
			st.giveItems(Scale, Drop);
		}
		return null;
	}
	
	public static void main(String[] args)
    {
    	new Q358_IllegitimateChildOfAGoddess(358, qn, "Illegitimate Child Of A Goddess");    	
	}


}			